/*
 * @Author: your name
 * @Date: 2021-04-07 15:36:33
 * @LastEditTime: 2024-11-09 11:13:38
 * @LastEditors: Lcx l1556461835@163.com
 * @Description: In User Settings Edit
 * @FilePath: \frontEnd\store\index.js
 */
import { IP } from "@/static/ipConfig";
export const strict = false;
export const state = () => ({
  IP: IP,
  gradeAll: [],
  gradeAllCal: [],
  gradeAllCalOb: [],
  gradeAllPltcm: [],
  gradeAllPltcmOb: [],
  pickerOptions: {
    shortcuts: [
      {
        text: "最近一周",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          picker.$emit("pick", [start, end]);
        }
      },
      {
        text: "最近一个月",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          picker.$emit("pick", [start, end]);
        }
      },
      {
        text: "最近三个月",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
          picker.$emit("pick", [start, end]);
        }
      }
    ]
  },
  chemicalName: {
    chem_c: "C",
    chem_si: "Si",
    chem_mn: "Mn",
    chem_p: "P",
    chem_s: "S",
    chem_nb: "Nb",
    chem_v: "V",
    chem_ti: "Ti",
    chem_mo: "Mo",
    chem_cu: "Cu",
    chem_n: "N",
    chem_ni: "Ni",
    chem_cr: "Cr",
    chem_al: "Al",
    chem_ca: "Ca",
    chem_h: "H",
    chem_as: "As",
    chem_b: "B",
    chem_be: "Be",
    chem_bi: "Bi",
    chem_ce: "Ce",
    chem_co: "Co",
    chem_la: "La",
    chem_mg: "Mg",
    chem_o: "O",
    chem_pb: "Pb",
    chem_pd: "Pd",
    chem_sb: "Sb",
    chem_se: "Se",
    chem_sn: "Sn",
    chem_ta: "Ta",
    chem_te: "Te",
    chem_w: "W",
    chem_zn: "Zn",
    chem_zr: "Zr"
  },
  menuData: [],
  user: {},
  tagNavList: [],
  tagNavModel: "",
  baseUrl: "",
  loginLogoPath: "",
  publicKey: "",
  apiGate: "",
  companyName: "",
  bigLogoPath: "",
  smallLogoPath: "",
  allMenus: "",
  localeInfo: [
    {
      type: "zh",
      name: "中文"
    },
    {
      type: "en",
      name: "English"
    }
  ],
  locales: ["zh", "en"],
  locale: "zh",
  fullScreen: false, // 全屏显示
  errorInfo: [], // 报警信息
  sharedId: "", // 表单id
  userID: ""
});

export const getters = {
  getJurisdiction: state => routeName => {
    var resources = state.user.resources;
    if (!state.user.resources) {
      var user = JSON.parse(localStorage.getItem("user"));
      resources = user.resources;
    }
    return resources.indexOf(routeName) > -1;
  },
  getSharedId: state => state.sharedId
};
export const mutations = {
  getJurisdiction: state => routeName => {
    var resources = state.user.resources;
    if (!state.user.resources) {
      var user = JSON.parse(localStorage.getItem("user"));
      resources = user.resources;
    }
    return resources.indexOf(routeName) > -1;
  },
  allMenus(state, allMenus) {
    state.allMenus = allMenus;
  },
  setUser(state, user) {
    if (!user) return;
    state.user = user;
  },
  SET_LANG(state, locale) {
    if (state.locales.indexOf(locale) !== -1) {
      state.locale = locale;
    }
  },
  setInitInfo(state, result) {
    state.publicKey = result.publicKey;
    state.apiGate = result.apiGate;
    if (!result.version) {
      return;
    }
    var versionInfo =
      typeof result.version.content === "string"
        ? JSON.parse(result.version.content)
        : result.version.content;
    state.companyName = versionInfo[0];
    state.bigLogoPath = (versionInfo[3] ? versionInfo[3] : "").split(":")[1]; // 找张默认图片
    state.smallLogoPath = (versionInfo[2] ? versionInfo[2] : "").split(":")[1];
    state.baseUrl =
      versionInfo.length < 5 ? "http://localhost:8099" : versionInfo[4];
    state.loginLogoPath = (versionInfo[5] ? versionInfo[5] : "").split(":")[1]; // 登录页logo
  },
  SET_ERROR_INFO(state, errorInfo) {
    if (state.errorInfo.length >= 50) {
      state.errorInfo.pop();
    }
    state.errorInfo.unshift(errorInfo);
  },
  setShareId(state, param) {
    state.sharedId = param;
  },
  SET_USER_ID(state, userID) {
    state.userID = userID;
  }
};

export const actions = {
  updateShareId({ commit }, param) {
    commit("setShareId", param);
  },
  setUserID({ commit }, userID) {
    if (userID) {
      localStorage.setItem("userID", userID);
    }
    commit("SET_USER_ID", userID);
  }
};
